# Table 6: Administrative Data


# 1. Load Packages ----

library(lfe)
library(stargazer)

# 2. Read in Data ----

load(file = "df_voxit_day_canton.RData")

load(file = "df_voxit_prop_canton.RData")

# 3. Regressions ----
## 3.a Turnout ----
# reg3
lm.robust3 <- felm(turnout_admin ~ utility_optc_sum + utility_optc_max + 
                     avg_male + avg_married + 
                     avg_age + avg_uni + avg_knowledge + avg_leftright | 
                     canton_id + year + prop_voxit | 0 | canton_id + datum_merge, 
                   data = voxit_day_canton_robust[voxit_day_canton_robust$prop_voxit>1,])
summary(lm.robust3)

# one std
summary(lm.robust3)$coefficients[1]*sd(voxit_day_canton_robust[voxit_day_canton_robust$prop_voxit>1,]$utility_optc_sum)
summary(lm.robust3)$coefficients[2]*sd(voxit_day_canton_robust[voxit_day_canton_robust$prop_voxit>1,]$utility_optc_max)



## 3.b Selective Abstention ----
# reg2
felm.out_empty2 <- felm(formula = sabst_admin ~ net_benefit + prop_nr_day | 
                          datum_merge + canton_id + prop_voxit | 0 | datum_merge + canton_id , 
                        data = voxit_prop_canton)
summary(felm.out_empty2)


# one std
sd(voxit_prop_canton$net_benefit)
sd(voxit_prop_canton$prop_nr_day)

# 3. Regression Table ----
stargazer(lm.robust3, felm.out_empty2,
          type = "latex",
          star.cutoffs = c(0.1, 0.05, 0.01),
          star.char = c("*", "**", "***"),
          summary=T,
          keep = c("^utility_optc_sum", "^utility_optc_max",
                   "^net_benefit", "prop_nr_day"),
          covariate.labels = c("U$^{sum}$", "U$^{max}$",
                               "Avg. net benefit", "Proposition ranking"),
          df = F,
          dep.var.caption="Dependent variable:",
          column.labels = c("Turnout", "Selective abstention"),
          dep.var.labels.include=F,
          float = F, 
          omit.table.layout ="n",
          keep.stat = c("n"),
          out = "Table6.tex")
































